package org.hackystat.ambientdevice.device.orb;

import static org.junit.Assert.assertEquals;
import static org.junit.Assert.fail;
import org.hackystat.ambientdevice.ConfigurationException;
import org.hackystat.ambientdevice.device.AmbientAction;
import org.hackystat.ambientdevice.device.orb.AmbientOrb.Animation;
import org.hackystat.ambientdevice.device.orb.AmbientOrb.Color;
import org.junit.Before;
import org.junit.Test;

/**
 * Test cases for the AmbientOrb's Actions. 
 * Including ChangeColor and ChangeAnimation.
 * 
 * @author Shaoxuan Zhang
 */
public class TestAmbientOrbActions {
  
  private static final String deviceId = "123-ABC-456";
  private AmbientOrb orb;
  
  /**
   * Initiate the Orb for test.
   */
  @Before
  public void setupOrb() {
    orb = AmbientOrb.getOrb(deviceId);
    orb.setAnim(Animation.NONE);
    orb.setColor(Color.RED);
    assertEquals("Orb's color should be RED.", Color.RED, orb.getColor());
    assertEquals("Orb's animation should be NONE.", Animation.NONE, orb.getAnim());
  }

  /**
   * Test the act method. Make sure it do change the state.
   * 
   * @throws ConfigurationException when parameters are not valid
   */
  @Test
  public void testAmbientOrbActions() throws ConfigurationException {
    AmbientAction changeColor = new ChangeColor(orb, "BLUE");
    AmbientAction changeAnimation = new ChangeAnimation(orb, "SLOW");
    changeColor.act();
    assertEquals("Orb's color should be BLUE now.", Color.BLUE, orb.getColor());
    changeAnimation.act();
    assertEquals("Orb's animation should be BLUE now.", Animation.SLOW, orb.getAnim());
  }
  
  /**
   * Test cases for action constructors. Make sure they can catch invalid parameter.
   */
  @Test
  public void testInvalidActions() {
    try {
      new ChangeColor(orb, "NOT_A_COLOR");
      fail("Exception should be thrown.");
    }
    catch (ConfigurationException e) {
      System.out.println("Expected ConfigurationException is caught");
    }
    try {
      new ChangeAnimation(orb, "NOT_AN_ANIMATION");
      fail("Exception should be thrown.");
    }
    catch (ConfigurationException e) {
      System.out.println("Expected ConfigurationException is caught");
    }
  }
}
